﻿using System;
using visinia.SmartEngine.Installer;
using System.Web.UI.WebControls;

namespace visinia.web.admin.pages
{
    public partial class InstallModule : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void UPLOAD_Click(object sender, EventArgs e)
        {
            Message.InnerText = InstallController.InstallModule(ModuleFile, CheckBoxSaveZip.Checked);
            Message.Visible = true;
        }

        protected void CANCEL_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.RawUrl);
        }

        protected void GridViewModules_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
                e.Row.Cells[3].Visible = (!((ContentFileInfo)e.Row.DataItem).IsInstalled);
        }

        protected void GridViewModules_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Install")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string ModuleName = GridViewModules.Rows[index].Cells[0].Text;
                string Package = GridViewModules.Rows[index].Cells[1].Text;
                string ZipFileName = GridViewModules.Rows[index].Cells[2].Text;
                MessageLocal.InnerText = InstallController.InstallModuleLocal(ModuleName, Package, ZipFileName);
                MessageLocal.Visible = true;
            }
        }
    }
}